﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media.Imaging;

/**
 * 创建时间：2014/12/15 13:55:14
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace ComicIsland.Common.Converter
{
    public class PivotHeaderImageConverter : IValueConverter
    {

        #region IValueConverter 成员

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            try
            {
                BitmapImage bitImage = new BitmapImage();
                TextBlock txt = (value as TextBlock);
                if (txt != null)
                {
                    string headerTitle = string.IsNullOrWhiteSpace(txt.Text) ? "" : txt.Text.Trim ();
                    switch (headerTitle.Trim())
                    {
                        case "书架":
                            bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Pivots/bookcase.png", UriKind.Relative); break;
                        case "书城":
                            bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Pivots/bookstore.png", UriKind.Relative); break;
                        case "分类":
                            bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Pivots/category.png", UriKind.Relative); break;
                        case "搜索":
                            bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Pivots/search.png", UriKind.Relative); break;
                        case "":
                        default:
                            bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Empty404.png", UriKind.Relative); break;
                    }
                }
                else
                {
                    bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Empty404.png", UriKind.Relative);
                }
                return bitImage;
            }
            catch (Exception err)
            {
                LogHelper.LogError(err.Message, this.GetType(), MethodBase.GetCurrentMethod());
                //图片异常，则使用默认的图片
                //return new Uri(Keys.RESOURCE_ASSEMBLYNAME + "/images/404.jpg", UriKind.Relative);
                BitmapImage bitImage = new BitmapImage();
                bitImage.UriSource = new Uri(KEYS.RESOURCE_ASSEMBLYNAME + "/Images/Empty404.png", UriKind.Relative);
                return bitImage;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }

        #endregion
    }
}
